package com.car.dal.dao.reserve;


import java.text.DecimalFormat;
import java.util.List;

import com.car.bean.GridObj;
import com.car.bean.OrderObj;
import com.car.bean.PageObj;
import com.car.dal.dao.ibatis.IbatisCommonDao;
import com.car.dal.object.TgReserve;
import com.car.util.MathUtil;
import com.car.util.Page;

public class TgReserveDaoImpl extends IbatisCommonDao<TgReserve, Long> implements TgReserveDao {
	private DecimalFormat df = new DecimalFormat("######0.00");
	
	public GridObj GetList(TgReserve reserve, PageObj pageObj) {
		OrderObj order = new OrderObj();
		order.setDir("desc");
		order.setSort("id");
		return super.findByPage(reserve, pageObj, order);
	}
	
	public Integer getReserveByTypeCount(TgReserve reserve) {
		return this.queryForInteger("getReserveByTypeCount", reserve);
	}
	
	public List<TgReserve> getReserveByType(TgReserve reserve , Page page) {
		reserve.setFirstrownum(page.getFirstrownum());
		reserve.setPagesize(page.getPagesize());
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByType", reserve);
		return list;
	}
	
	public List<TgReserve> getReserveByKeyname(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByKeyname", reserve);
		return list;
	}
	
	public Integer getReserveCouByUsername(TgReserve reserve) {
		return this.queryForInteger("getReserveCouByUsername", reserve);
	}
	
	public List<TgReserve> getReserveByUsername(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByUsername", reserve);
		return list;
	}
	
	public Integer getTrackingCount(TgReserve track) {
		return this.queryForInteger("getTrackingCount", track);
	}
	
	public List<TgReserve> getTrackingByKeyname(TgReserve reserve , Page page) {
		reserve.setFirstrownum(page.getFirstrownum());
		reserve.setPagesize(page.getPagesize());
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getTrackingByKeyname", reserve);
		return list;
	}
	
	public List<TgReserve> getReserveByTime(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByTime", reserve);
		return list;
	}
	
	public List<TgReserve> getReserveByDateAndTime(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByDateAndTime", reserve);
		return list;
	}
	
	public Integer getReserveCount(TgReserve track) {
		return this.queryForInteger("getReserveCount", track);
	}
	
	public List<TgReserve> getReserveList(TgReserve reserve , Page page) {
		reserve.setFirstrownum(page.getFirstrownum());
		reserve.setPagesize(page.getPagesize());
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveList", reserve);
		return list;
	}
	
	public List<TgReserve> getReserveByDate(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserveByDate", reserve);
		return list;
	}
	
	public List<TgReserve> getReserve(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserve", reserve);
		return list;
	}
	
	public List<TgReserve> getReserve2(TgReserve reserve) {
		List<TgReserve> list=this.queryForEntityList(TgReserve.class,"getReserve2", reserve);
		return list;
	}
	
	//本月预约统计
	public Integer getZonReserveCountBy(TgReserve reserve) {
		return this.queryForInteger("getZonReserveCountBy", reserve);
	}
	public Integer getShidaoReserveCountBy(TgReserve reserve) {
		return this.queryForInteger("getShidaoReserveCountBy", reserve);
	}
	public Integer getFeiCepReserveCountBy(TgReserve reserve) {
		return this.queryForInteger("getFeiCepReserveCountBy", reserve);
	}
	
	public Integer getReserveCountByTime(TgReserve reserve) {
		return this.queryForInteger("getReserveCountByTime", reserve);
	}

	@Override
	public Integer getReserveCountByTime2(TgReserve reserve) {
		return this.queryForInteger("getReserveCountByTime2", reserve);
	}
	/**
	 * 获取 当日 城市 的中心名称
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<String> getYy_JdCenter(String province,String startTime) {
		TgReserve reserve = new TgReserve();
		reserve.setProvince(province);
		reserve.setStartTime(startTime);
		return this.queryForList("getYy_JdCenter", reserve);
	}
	/**
	 * 获取预约接待的老师
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<String> getYy_JdTeacher(String province, String startTime) {
		TgReserve reserve = new TgReserve();
		reserve.setProvince(province);
		reserve.setStartTime(startTime);
		return this.queryForList("getYy_JdTeacher", reserve);
	}

	@Override
	public TgReserve getTg_reserve_Id(String Id) {
		TgReserve reserve = new TgReserve();
		reserve.setId(Integer.parseInt(Id));
		List<TgReserve> reserves = findByExample(reserve);
		if(MathUtil.isNotEmpty(reserves)) {
			return reserves.get(0);
		}
		return null;
	}

	@Override
	public String getYydfl(String username,String date) {
		TgReserve reserve = new TgReserve();
		reserve.setUsername_2(username);
		reserve.setStartTime(date);
		double yyrs = this.queryForInteger("getYydfCounts", reserve);//预约人数
		reserve.setState(2);//已出现
		double ydrs = this.queryForInteger("getYydfCounts", reserve);//已到人数
		if(yyrs == 0) 
			return "0";
		return Double.valueOf(df.format(ydrs/yyrs))*100+"%";
	}

	@Override
	public String getQrdfl(String reception_u, String date) {
		TgReserve reserve = new TgReserve();
		reserve.setReception_u(reception_u);
		reserve.setStartTime(date);
		double jdrs = this.queryForInteger("getQrdfCounts", reserve);//接待人数
		reserve.setState(2);//已出现
		double ydrs = this.queryForInteger("getQrdfCounts", reserve);//已到人数
		if(jdrs == 0) 
			return "0";
		return Double.valueOf(df.format(ydrs/jdrs))*100+"%";
	}
}
